<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>导入CSV文件</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .upload-container {
            max-width: 600px;
            margin: 50px auto;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 5px;
            background-color: #f9f9f9;
        }
        .file-format {
            margin-top: 20px;
            padding: 15px;
            background-color: #e9ecef;
            border-radius: 5px;
        }
        .button-container {
            margin-top: 20px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="upload-container">
            <h2 class="text-center mb-4">导入CSV文件</h2>
            
            <div th:if="${message}" class="alert alert-info" th:text="${message}"></div>
            
            <form th:action="@{/import/csv}" method="post" enctype="multipart/form-data">
                <div class="mb-3">
                    <label for="file" class="form-label">选择CSV文件</label>
                    <input type="file" class="form-control" id="file" name="file" accept=".csv" required>
                </div>
                <div class="d-grid">
                    <button type="submit" class="btn btn-primary">上传并导入</button>
                </div>
            </form>
            
            <div class="button-container">
                <div class="d-grid">
                    <button id="createCollectionButton" class="btn btn-secondary">创建集合</button>
                </div>
            </div>
            
            <div class="file-format">
                <h5>文件格式说明：</h5>
                <p>请确保CSV文件包含以下列：</p>
                <ul>
                    <li>question - 问题文本</li>
                    <li>answer - 答案文本</li>
                </ul>
                <p>示例：</p>
                <pre>
question,answer
"什么是Java？","Java是一种面向对象的编程语言"
"什么是Spring Boot？","Spring Boot是一个用于简化Spring应用开发的框架"
                </pre>
            </div>
        </div>
    </div>
    
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        document.getElementById('createCollectionButton').addEventListener('click', function() {
            fetch('/import/create-collection', {
                method: 'POST'
            })
            .then(response => response.json())
            .then(data => {
                alert(data.message);
            })
            .catch(error => {
                console.error('Error:', error);
                alert('创建集合失败');
            });
        });
    </script>
</body>
</html> 